/**
 * 文本元素 (数据类)
 */
function sText(target) {
    if(this.initialize) return;

    var thiz = target ? target : this;

    sElement.call(this, "sText");

    if(thiz.placeholder){
        this.placeholder = thiz.placeholder;
    }

    if(thiz.placeholderColor){
        this.placeholderColor = thiz.placeholderColor;
    }
    
    var innerText = thiz.innerText ? ("" + thiz.innerText) : "";
    var style = {
        fontSize: 11,
        fontFamily: "宋体",
        color: "#000",
        ...thiz._pStyle,
        ...thiz.style
    }

    /**
     * 定义innerText
     */
    Object.defineProperty(this, "innerText", { 
        get: function(){
            return innerText;
        },
        set: function(val){
            innerText = val == null ? "" : val.toString();
        },
        enumerable: true
    });

    /**
     * 定义style
     */
    Object.defineProperty(this, "style", { 
        get: function(){
            return style;
        },
        set: function(val){
            if(!val || typeof(val) !== "object") return;
            for(let i in val){
                style[i] = val[i];
            }
        },
        enumerable: true
    });

    if(thiz.variable){
        this.variable = thiz.variable;
    }
}

/**
 * 获取字体样式
 * @param {*} ratio 
 * @param {*} opt 
 * @returns 
 */
sText.prototype.getFontStyle = function (ratio, opt) {
    var style = "";

    if(this.style.fontStyle){
        style += this.style.fontStyle + " ";
    }

    if (this.style.fontWeight) {
        style += this.style.fontWeight + " ";
    }

    if (this.style.fontSize) {
        let fontSize = this.style.sub || this.style.sup 
            ? this.style.fontSize / 2 
            : this.style.fontSize;
        style += (parseFloat(fontSize) * 
            parseFloat(ratio ? ratio : 1)).toFixed(4) + "px ";
    }

    if(opt && opt.fontFamily){
        style += opt.fontFamily + " ";
    }else if (this.style.fontFamily) {
        style += this.style.fontFamily + " ";
    }

    return style;
}

/**
 * 将sElement原型上的方法和属性赋值给sText原型
 */
for(let i in sElement.prototype){
    sText.prototype[i] = sElement.prototype[i];
}

/**
 * 克隆方法
 */
sText.prototype.clone = function(){
    let text = new sText(this);
    return text;
}
